package com.zzty.txj.serviceImpl;


import com.alibaba.fastjson.JSONObject;
import com.zzty.txj.dao.DpostMapper;
import com.zzty.txj.entity.*;
import com.zzty.txj.service.DpostService;
import com.zzty.txj.util.HttpUtil;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.zzty.txj.util.HttpUtil.httpGet;

@Service
public class DpostServiceImpl implements DpostService {
    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(DpostServiceImpl.class);
    @Autowired
    DpostMapper dpostMapper;

    @Value("${url.user.getUserByOpenId}")
    String url;

    @Override
    public User getUser(User user){
        String us=null;
        User user1=new User();
        try {
            //us = httpGet(url+user.getOpenId());
             us=httpGet(url+user.getOpenId());
           logger.info("DpostServiceImplOpenId"+user.getOpenId());

           // us=HttpUtil.httpGet(url+user.getOpenId());
            logger.info("us|"+us);
            user1=JSONObject.parseObject(us,User.class);
            logger.info("user1"+user1);

        } catch (Exception e) {
            e.printStackTrace();
        }
       // List<Clazz> clazzes=JSONObject.parseArray(us,Clazz.class);
//        User user1=dpostMapper.getUser(user);
        return user1;
    }

    public Daily getDaily(int id){
        Daily daily=dpostMapper.getDaily(id);
        return daily;
    }
//    public Integer getCount(String date){
//        Integer count=dpostMapper.getCount(date);
//        return count;
//    }
    public Daily getDaily1(Integer id){
        Daily daily=dpostMapper.getDaily1(id);
        return daily;
    }

    public Location getLocation(Integer id){
        Location location=dpostMapper.getLocation(id);
        return location;
    }


    public Integer getCount(DoDaily doDaily){
        Integer count=dpostMapper.getCount(doDaily);
        return count;
    }

    public List<DoDaily> getDoDaily(DoDaily doDaily){
        List<DoDaily>doDailies=dpostMapper.getDoDaily(doDaily);

        return doDailies;
    }
}
